home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-01-30 | 5.7 KB | 214 lines | [TEXT/IGR0] |
- // Split Axis, Version 1.1, LH951107
- // See the Split Axis Example experiment for documentation
-
- // Version 1.1 created to be liberal name aware and data folder savvy
-
- #include <Keyword-Value>
- #include <Readback ModifyStr>
- #include <Graph Utility Procs>
-
-
- #pragma rtGlobals=1 // This mainly acts as notice that this proc is Igor 3.0 savvy
-
-
- Macro SplitAxis(axName,splitPoint,splitGap)
- String axName="left"
- Prompt axName,"axis to split",popup AxisList("")
- Variable splitPoint= 80
- Prompt splitPoint,"% along axis to place split"
- Variable splitGap= 8
- Prompt splitGap,"Size of gap in Points"
-
- DoSplitAxis(axName,splitPoint/100,splitGap)
- End
-
- // this routine finds the last trace on the top graph. It is used right
- // after appending a new trace to a graph to find out the full trace name
- // of that new trace. The wave name alone is not sufficient.
- // This routine ASSUMES the last trace is not the only trace
- //
- Function/S WMSA_GetLastTraceName() // funny name to avoid any possible future conflict
- Variable p0,p1 // for walking down the list
- Variable semicolon= char2num(";")
-
- String list=TraceNameList("", ";", 1)
- p1= strlen(list)-2 // index of last char before semicolon
- p0= p1-1
- do
- if( char2num(list[p0]) == semicolon )
- break
- endif
- p0-=1
- while(p0>0) // emergency exit only
-
- return list[p0+1,p1]
- end
-
-
-
- Proc DoSplitAxis(axName,splitPoint,splitGap)
- String axName;Variable splitPoint,splitGap
-
- PauseUpdate; Silent 1
-
- String newAxis
- Variable i=2
- do
- newAxis= axName+"_P" +num2istr(i) | name of new axis; left_P2
- if( strlen(AxisInfo("",newAxis)) == 0 )
- break;
- endif
- i+=1
- while(1)
-
- String axInfo= AxisInfo("",axName),axType
- axType= StrByKey("AXTYPE",axInfo)
- if( strlen(axType) == 0 )
- Abort "FOOBAR" | sanity check, from now on we ASSUME things work
- endif
- Variable isX= (CmpStr("bottom", axType)==0 ) %| (CmpStr("top", axType)==0 )
-
- String tracesOnGraph= TraceNameList("", ";", 1)
- String thetrace,tInfo,otheraxis,oaInfo,oaType
- String theCmd | command string is built up here
- String key1,key2
- Variable/D av0,av1,sp
- Variable origStart,origEnd,split | original axis start and end fractions, split point on axis
-
- GetAxis/Q $axName
- av0= V_Min; av1= V_max
-
- i=0
- do
- thetrace= GetStrFromList(tracesOnGraph,i,";")
- if( strlen(thetrace) == 0 )
- break;
- endif
-
- tInfo= TraceInfo("",thetrace,0)
- if( isX )
- key1= "XAXIS"
- key2= "YAXIS"
- else
- key1= "YAXIS"
- key2= "XAXIS"
- endif
- if( CmpStr(axName,StrByKey(key1,tInfo))== 0 )
- otheraxis= StrByKey(key2,tInfo)
- oaInfo= AxisInfo("",otheraxis)
- oaType= StrByKey("AXTYPE",oaInfo)
- theCmd= "AppendToGraph/"+oaType[0]+"="+otheraxis+"/"+axType[0]+"="+newAxis+" "
- theCmd += GetWavesDataFolder(TraceNameToWaveRef("", thetrace), 4)
- if( strlen(StrByKey("XWAVE",tInfo)) != 0 )
- theCmd += " vs "+GetWavesDataFolder(XWaveRefFromTrace("", thetrace), 4)
- endif
- Execute theCmd
- CopyTraceSettings(thetrace,-1,WMSA_GetLastTraceName(),-1)
- endif
-
- I+=1
- while(1)
- CopyAxisSettings(axName,newAxis)
- origStart= GetNumFromModifyStr(axInfo,"axisEnab","{",0)
- origEnd= GetNumFromModifyStr(axInfo,"axisEnab","{",1)
- sp= splitPoint*(av1-av0)+av0
-
- GetWindow kwTopWin,psize
- if( isX )
- splitGap= splitGap/(2*(V_right-V_left))
- else
- splitGap= splitGap/(2*(V_bottom-V_top))
- endif
- | splitGap *= origEnd-origStart
-
- split= splitPoint*(origEnd-origStart)+origStart
- if( splitPoint < 0.5 ) | leave original axis with biggest piece
- SetAxis $axName,sp,av1
- SetAxis $newAxis,av0,sp
- ModifyGraph axisEnab($axName)={split+splitGap,origEnd}
- ModifyGraph axisEnab($newAxis)={origStart,split-splitGap}
- else
- SetAxis $axName,av0,sp
- SetAxis $newAxis,sp,av1
- ModifyGraph axisEnab($axName)={origStart,split-splitGap}
- ModifyGraph axisEnab($newAxis)={split+splitGap,origEnd}
- endif
- ModifyGraph standoff($axName)=0, freePos($axName)=0
- ModifyGraph standoff($newAxis)=0, freePos($newAxis)=0
- end
-
-
- Macro AddSplitAxisMarks(axName1,axName2)
- String axName1="left",axName2= "left_P2"
- Prompt axName1,"axis 1",popup AxisList("")
- Prompt axName2,"axis 2",popup AxisList("")
-
- DoAddSplitAxisMarks(axName1,axName2)
- End
-
-
-
- Proc DoAddSplitAxisMarks(axName1,axName2)
- String axName1,axName2
-
- PauseUpdate; Silent 1
-
- Variable SLASH_LEN= 5,SLASH_HEIGHT=2 | these params determine size and angle of slash
- String axInfo1= AxisInfo("",axName1),axInfo2= AxisInfo("",axName2)
- String axType1,axType2
- axType1= StrByKey("AXTYPE",axInfo1)
- axType2= StrByKey("AXTYPE",axInfo2)
- if( CmpStr(axType1,axType2)!= 0 )
- Abort "Different kinds of axes - unlikely" | sanity check
- endif
- Variable isX= (CmpStr("bottom", axType1)==0 ) %| (CmpStr("top", axType1)==0 )
-
- Variable a1start,a2start,a1end,a2end
-
- a1start= GetNumFromModifyStr(axInfo1,"axisEnab","{",0)
- a1end= GetNumFromModifyStr(axInfo1,"axisEnab","{",1)
- a2start= GetNumFromModifyStr(axInfo2,"axisEnab","{",0)
- a2end= GetNumFromModifyStr(axInfo2,"axisEnab","{",1)
- if( a1end > a2start ) | user chose axes in reverse order
- a1end= a2end
- a2start= a1start
- endif
- GetWindow kwTopWin,psize
- Variable x0= V_left, y0= V_top,dx= V_right-V_left,dy= V_bottom-V_top,x,y
- Variable sh,sl
-
- SetDrawLayer UserFront
- SetDrawEnv gstart
- if( isX )
- x= a1end
- if( CmpStr("bottom", axType1)==0 )
- y= 1
- else
- y= 0
- endif
- sh= SLASH_HEIGHT/dx
- sl= SLASH_LEN/dy
- SetDrawEnv xcoord= prel,ycoord= prel
- DrawLine x-sh,y-sl,x+sh,y+sl
- x= a2start
- SetDrawEnv xcoord= prel,ycoord= prel
- DrawLine x-sh,y-sl,x+sh,y+sl
- else
- y= 1-a1end
- if( CmpStr("right", axType1)==0 )
- x= 1
- else
- x= 0
- endif
- sh= SLASH_HEIGHT/dy
- sl= SLASH_LEN/dx
- SetDrawEnv xcoord= prel,ycoord= prel
- DrawLine x-sl,y-sh,x+sl,y+sh
- y= 1-a2start
- SetDrawEnv xcoord= prel,ycoord= prel
- DrawLine x-sl,y-sh,x+sl,y+sh
- endif
- SetDrawEnv gstop
- end
-
-